cmake_minimum_required(VERSION 3.10)

# 设置项目名
project(KiteEngine)

# 设置使用C++ 20标准
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED on)

# 指定字符集
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")

# 添加头文件搜索路径
include_directories(${PROJECT_SOURCE_DIR}/Engine)

# 查找静态库里的所有.h、.cpp以及shader文件
file(GLOB_RECURSE KiteHeader ${PROJECT_SOURCE_DIR}/Engine/*.h)
file(GLOB_RECURSE KiteSource ${PROJECT_SOURCE_DIR}/Engine/*.cpp)
file(GLOB_RECURSE KiteShader ${PROJECT_SOURCE_DIR}/Shaders/*.*)

# 源文件分组
source_group(TREE "${PROJECT_SOURCE_DIR}/Engine" PREFIX "Sources" FILES ${KiteHeader} ${KiteSource})
source_group(TREE "${PROJECT_SOURCE_DIR}/Shaders" PREFIX "Shaders" FILES ${KiteShader})

# 生成静态库
add_library(Engine STATIC ${KiteHeader} ${KiteSource} ${KiteShader})
set_property(TARGET Engine PROPERTY COMPILE_WARNING_AS_ERROR ON)

# 链接 DirectX 12 核心库
target_link_libraries(Engine PRIVATE d3d12.lib dxgi.lib d3dcompiler.lib)

# 设置 Unicode 字符集
target_compile_definitions(Engine PRIVATE UNICODE _UNICODE)

# 设置Visual Studio增量构建
target_compile_options(Engine PUBLIC "/ZI")
target_link_options(Engine PUBLIC "/INCREMENTAL")
target_compile_options(Engine PRIVATE /bigobj)

# 将hlsl视为文本文件
set_source_files_properties(${KiteShader} PROPERTIES HEADER_FILE_ONLY TRUE)

# 生成可执行文件
add_executable(KiteEngine main.cpp)

# 设置Windows子系统
target_link_options(KiteEngine PRIVATE "/SUBSYSTEM:WINDOWS")

# 链接静态库
target_link_libraries(KiteEngine PRIVATE Engine user32.lib gdi32.lib)

# 设置工作目录
set_target_properties(KiteEngine PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")